<template>
  <div>
    <div class="e-box">
      <div class="tit">
        赏金规则
      </div>

      {{ brokerRule }}
    </div>
    <fTitle :tit="'经纪人详情'" />
    <div class="xq-form-wrapper">
      <a-spin :spinning="spinning" class="xq-form-content" style="margin-top: 24px">
        <XqTable
          :customize="FormJson['config']['table']['customize']"
          :scroll="{ x: columns.length * 150 }"
          :pagination="false"
          :dataSource="tableData"
          :columns="columns"
          :row-selection="
            FormJson['config']['table']['extend']['batch']
              ? {
                  selectedRowKeys: selectedRowKeys,
                  onChange: onSelectChange
                }
              : null
          "
          class="xq-form-content-table"
          @change="onTableChange"
        >
          <template v-for="(col, index) in columns" v-slot:[`xq_${col.dataIndex}`]>
            <span :key="index">
              {{ col.customTitle }}
            </span>
          </template>
          <!-- eslint-disable-next-line prettier/prettier -->
          <template v-for="(col, index) in columns" v-slot:[col.dataIndex]="text, record">
            <span v-if="col.dataIndex === 'brokerName'" :key="index"> <img :src="record.avatar" class="avatar" /> {{ text }} </span>
            <span v-else-if="col.dataIndex === 'PositionCount'" :key="index">
              {{ text ? text : 0 }}
            </span>
            <span v-else-if="col.dataIndex === 'brokerCreate'" :key="index">
              {{ text }}
              <!-- {{ text ? moment(text).format("YYYY-MM-DD") : "" }} -->
            </span>
            <XqTableCell v-else :key="index" :record="record" :field="FormJson['fields'][col.dataIndex]" :dynamicData="dynamicData" />
          </template>
        </XqTable>
        <div class="xq-form-content-pagination">
          <div class="xq-form-content-pagination-total">共 {{ total }} 条</div>
          <a-pagination
            v-model="pageNo"
            :page-size="pageSize"
            :total="total"
            :show-size-changer="true"
            :show-quick-jumper="true"
            :page-size-options="['10', '20', '50', '100']"
            @change="onPageChange"
            @showSizeChange="onPageSizeChange"
          />
        </div>
      </a-spin>
    </div>
  </div>
</template>

<script>
import fTitle from "../../../../component/fTitle";
import FormJson from "./FormJson";
import XqCurdMixin from "xqjr-plugin-form/mixins/XqCurdMixin";
import { getPostBrokerInfo } from "../../../api";
const curdMixin = new XqCurdMixin({
  FormJson,
  tableConfigKey: "table"
});

export default {
  mixins: [curdMixin],
  components: {
    fTitle
  },
  props: {
    brokerRule: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      spinning: false,
      tableData: [],
      total: 0,
      pageNo: 1,
      pageSize: 20
    };
  },
  created() {
    this.onGetPostBrokerInfo();
  },
  methods: {
    async onGetPostBrokerInfo() {
      try {
        this.spinning = true;
        const { data } = await getPostBrokerInfo({
          postId: this.$route.query.id,
          pageNo: this.pageNo,
          pageSize: this.pageSize
          // "orders[0].property": "brokerCreate",
          // "orders[0].desc": true
        });
        this.tableData = data.entities;
        this.total = data.entityCount;
        setTimeout(() => (this.spinning = false), 500);
      } catch (err) {
        console.log("error log --> ", err);
        setTimeout(() => (this.spinning = false), 500);
      }
    },
    onPageChange(page) {
      this.pageNo = page;
      this.onGetPostBrokerInfo();
    },
    onPageSizeChange(current, pageSize) {
      this.pageNo = 1;
      this.pageSize = pageSize;
      this.onGetPostBrokerInfo();
    }
  }
};
</script>

<style lang="scss" scoped>
.e-box {
  width: 100%;
  height: 140px;
  background: #faf9f9;
  border-radius: 4px;
  padding: 24px;
  .tit {
    font-size: 16px;
    margin-bottom: 12px;
  }
}
.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
</style>
